<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="app">


  </div>
  <!-- 引入React依赖 -->
  <script src="../React/react.development.js"></script>
  <script src="../React/react-dom.development.js"></script>
  <script src="../React/babel.min.js"></script>

  <!-- 编写React代码 -->
  <script type="text/babel">
    class App extends React.Component {
      constructor() {
        super()
        //定义变量
        this.state = {
          isLogin: false,
        }
      }
      render() {
        const { isLogin } = this.state

        // 方案1：通过if判断（逻辑代码非常多的情况）
        let welcome = null

        if (isLogin) {
          welcome = <h2>欢迎回来</h2>
        } else {
          welcome = <h2>请先登录</h2>
        }

        return (
          <div>
            {/* 方案1：通过if判断（逻辑代码非常多的情况） */}
            {welcome}

            {/* 方案2：三元运算符 */}
            <button onClick={e => this.btnLogin()}>{isLogin ? "退出" : "登录"}</button>
            <hr />

            {/* 方案3：逻辑与 */}
            {/* <h2>{isLogin && "你好啊，why"}</h2> */}
            
            {isLogin && <h2>你好啊，why</h2>}
          </div>
        )
      }

      btnLogin() {
        this.setState({
          isLogin: !this.state.isLogin,
        })

      }
    }
  </script>

  <script type="text/babel">
    ReactDOM.render(<App />, document.getElementById("app"))
  </script>

</body>

</html>